package com.lcj.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {

    @RequestMapping("/showlogin")
    public String showLogin(){

        return "login";
    }

    @RequestMapping("/login")
    public ModelAndView doLogin(String username,String password)
    {
        ModelAndView modelAndView = new ModelAndView();
        if("admin".equals(username)&&"123456".equals(password))
        {
            modelAndView.addObject("username",username);
            modelAndView.setViewName("success");
        }else
        {
            modelAndView.addObject("errorMsg","用户名密码错误");
            modelAndView.setViewName("login");
        }
        return modelAndView;

    }

    @RequestMapping("/login2")
    public String doLogin2(String username, String password, Model model)
    {
        if("admin".equals(username)&&"123456".equals(password))
        {
            model.addAttribute("usernmae",username);
            return "success";
        }else
        {
            model.addAttribute("errorMsg","用户名密码错误");
            return "redirect:showlogin";
        }
    }
}
